package org.springcloud.wisdom.springcloud_03_freshman.student.service;

import org.springcloud.wisdom.springcloud_03_freshman.index.login.entity.Freshman;
import org.springcloud.wisdom.springcloud_03_freshman.index.login.entity.Student;
import org.springcloud.wisdom.springcloud_03_freshman.student.dao.FreshmanDao;
import org.springcloud.wisdom.springcloud_03_freshman.student.dao.StudentDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class StudentService {
    @Autowired
    StudentDao studentDao;
    @Autowired
    FreshmanDao freshmanDao;

    /**
     * 根据sid修改学生信息
     * @param student 学生实体类
     * @return
     */
    @Transactional
    public boolean update(Student student){
        if (student ==null){
            return  false;
        }
        if (student.getSid() == null ||
                student.getSid().trim().length() <9 || student.getSid().trim().length()>9){
            return false;
        }
        Freshman freshman=new Freshman();
        freshman.setAddress(student.getAddress());
        freshman.setEmail(student.getEmail());
        freshman.setPhone(student.getPhone());
        freshmanDao.UpdateFreshmanBySid(freshman);
        return studentDao.updateStudentBySid(student)>0;
    }
}
